//文档加载
window.addEventListener('load',function(){
    let oSetbg = $$('#setbground'),
        bgImg = $$('#deskbg1'),
        oBg = $$('#bgWindow'),
        wrapDesk = $$('#wrap'),             //桌面
        deskTask = $$('#task'),             //任务栏
        aImg = $$('<img>',oBg),
        oMask = $$('#mask'),                //??
        fenlei = $$('#fenlei'),
        deskContents = $$('#deskContent'),
        maskImg = $$('<img>',oMask)[0],
        parents = $$('#deskContent'),       //桌面节点
        fenleiImg = fenlei.getElementsByTagName('img')[0],
        dateClass1 = createElem('h2'),      //常用分类
        dateClass2 = createElem('h2'),      //常用分类2
        clock = createElem('div'),          //万历年容器
        daiBaiDiv = createElem('div'),
        myselfDiv = createElem('div'),          /*个人会员*/
        week = createElem('p'),             //星期
        dateEvery = createElem('p'),        //日期
        lunra = createElem('p'),            //农历
        daiBaiTitle = createElem('p'),
        daiBaiNum = createElem('p'),
        img = ['images/bg1.jpg','images/bg2.jpg','images/bg3.jpg','images/bg4.jpg','images/bg5.jpg','images/bg6.jpg'];

    //检测浏览器版本
    // if(browInfo() == 'IE8'||browInfo() == 'IE7'||browInfo() == 'IE6'){
    //     alert('sorry,'+browInfo());
    //     return ;
    // }

    //runnig
    fnMove(oMask,{opacity:1},function (){
        oMask.style.display = 'block';
    });

    for(let i=0,len = aImg.length; i < len; i++){
        aImg[i].src = img[i];
    }

    try{
        bgImg.src = localStorage.deskBg || img[3];
    }catch(e){};

    //初始化桌面
    // new desk().init();

    //创建标题
    // dateClass1.innerText = '系统设置';
    // dateClass1.className = 'dateClass1'
    // dateClass2.innerText = '第三方应用';
    // dateClass2.className = 'dateClass2'
    // parents.insertBefore(dateClass1,parents.children[0]);
    // parents.insertBefore(dateClass2,parents.children[4]);

    //万历年
    var wanObj = wanLi();
    var jsonRiLi = {};
    jsonRiLi.webSrc='other/wanli/index.html';/*代办事项的地址*/
    jsonRiLi.title='万历年';
//  jsonRiLi.iWidth='900';/*待办是这个长度和大小的*/
	jsonRiLi.iWidth='680'
    jsonRiLi.iHeight='596';
    jsonRiLi.appCode ='daiban578596daiban578596daiban578596';/*伪装成特殊的appcode，这样可以不用全屏打开*/
    clock.className = 'clock';
    clock.id = 'clock';
    week.innerText = wanObj.weekDisplay;
    dateEvery.innerText = wanObj.todayRi;
    lunra.innerText = wanObj.lunarDay;              //农历日期日历
    clock.appendChild(week);
    clock.appendChild(dateEvery);
    clock.appendChild(lunra);
    wrapDesk.appendChild(clock);
    clock.onclick = function(){
        new newWindow(parents,deskTask,'clockid',jsonRiLi).initFix();
    };

    /*代办事项*/
   let daiBaiObj = new daiBai();
   let json = {};
   json.webSrc='daiBanShiXiang.html';/*代办事项的地址*/
   json.title='待办';
   json.iWidth='578';/*待办是这个长度和大小的*/
   json.iHeight='596';
   json.appCode ='daiban578596daiban578596daiban578596';/*伪装成特殊的appcode，这样可以不用全屏打开*/
   daiBaiDiv.className = 'daiBaiDiv';
   daiBaiDiv.id = 'daiBaiDiv';
   daiBaiTitle.innerText='待办';
   daiBaiTitle.className='daiBaiTitle';
   daiBaiNum.className='daiBaiNum';
   daiBaiNum.innerText = daiBaiObj.daiBaiNum;
   daiBaiDiv.appendChild(daiBaiTitle);
   daiBaiDiv.appendChild(daiBaiNum);
   wrapDesk.appendChild(daiBaiDiv);
   daiBaiDiv.onclick = function(){
        new newWindow(parents,deskTask,'daiBaiDiv',json).initFix();
    };

    //桌面端加样式，每个App的底色都要不同相邻的两个。通过DOM来操控它们之间的div底色。
    setTimeout(function(){
        var desk1 = document.getElementById('desk1'),
            desk2 = document.getElementById('desk2'),
            desk3 = document.getElementById('desk3'),
            desk4 = document.getElementById('desk4'),
            desk5 = document.getElementById('desk5'),
            desk6 = document.getElementById('desk6');

        try{
            desk1.firstChild.style.background = '#efb336';
            desk1.children[1].style.background = '#1f53a0';
            desk1.children[2].style.background = '#807f7f';
            desk1.children[3].style.background = '#b00f0f';
            desk1.children[4].style.background = '#a87c2c';
            desk1.children[5].style.background = '#0057bd';
        }catch(err){

       }
       try{
            desk2.firstChild.style.background = '#807f7f';
            desk2.children[1].style.background = '#efb336';
            desk2.children[2].style.background = '#1f53a0';
            desk2.children[3].style.background = '#b00f0f';
            desk2.children[4].style.background = '#a87c2c';
            desk2.children[5].style.background = '#0057bd';
       }catch(err){

       }
       try{
            desk3.firstChild.style.background = '#efb336';
            desk3.children[1].style.background = '#1f53a0';
            desk3.children[2].style.background = '#807f7f';
            desk3.children[3].style.background = '#b00f0f';
            desk3.children[4].style.background = '#a87c2c';
            desk3.children[5].style.background = '#0057bd';

            desk4.firstChild.style.background = '#efb336';
            desk4.children[1].style.background = '#1f53a0';
            desk4.children[2].style.background = '#807f7f';
            desk4.children[3].style.background = '#b00f0f';
            desk4.children[4].style.background = '#a87c2c';
            desk4.children[5].style.background = '#0057bd';

            desk5.firstChild.style.background = '#efb336';
            desk5.children[1].style.background = '#1f53a0';
            desk5.children[2].style.background = '#807f7f';
            desk5.children[3].style.background = '#b00f0f';
            desk5.children[4].style.background = '#a87c2c';
            desk5.children[5].style.background = '#0057bd';

            desk6.firstChild.style.background = '#807f7f';
            desk6.children[1].style.background = '#efb336';
            desk6.children[2].style.background = '#1f53a0';
            desk6.children[3].style.background = '#b00f0f';
            desk6.children[4].style.background = '#a87c2c';
            desk6.children[5].style.background = '#0057bd';
        }catch(err){

       }

    },1200);

    deskContents.style.marginLeft = '160px';



},false);

//jquery operator
$(function(){
    //桌面阻止冒泡行为
    $('#desk').on('mousedown',function(e){
        e.stopPropagation();
        $('#bgWindow').hide();
    });


    /*设置定时，4分钟获取一次*/
  	setInterval(function(){
  		let num = getDaiBaiNum();
//		alert(num);
		$("#daiBaiDiv .daiBaiNum").html(num);
  	},240000)

    //桌面左上角的分类图标
    // $('#wrap').append('<div class="fenlei" id="fenlei"><img src="./images/new/fenlei.png" /></div>');
    $('#wrap').append('<div class="fenlei" id="fenlei"></div>');

    //桌面左上角的欢迎语
    axios.get(zuulHost+'/uaa/user/getCurrentUserInfo?access_token='+accessToken,{
        })
        .then(function(res){
            console.log(res);
			if(res.data.data.name!=''){
				userNameAll = res.data.data.name/*全名，全局变量*/
				userName = res.data.data.name.substr(res.data.data.name.length-1,1);
        localStorage.role = res.data.data.role;
        localStorage.loginId = res.data.data.loginId;
				console.log(localStorage.role);/*最后一个字,全局变量*/
			}
            $('#wrap').append('<div class="welcome" >'+res.data.data.name+ '&nbsp; 你好，欢迎使用</div>');



        })
        .catch(function(err){
    });


    //桌面主题,壁纸,个人设置
    let bgwin = $('.bgwindow .windowMenuTitel li'),
        ulOne = $('#ulWindowOne'),
        ulTwo = $('#ulWindowTwo'),
        ulThree = $('#ulWindowThree'),
        ulTheme = $('.ulTheme li'),
        ulWindowOne = $('#ulWindowOne li'),
        leftBar = $('#leftBar'),
        task = $('#task'),
        taskMenu = $('#task .taskMenu')
        deskWrap = $('#deskWrap')
        deskWrap2 = $('#deskWrap2')
        deskWrap3 = $('#deskWrap3')
        wrap = $('#wrap')
        buttonLeft = $('#button_left')
        buttonRight = $('#button_right')
        deskss = document.getElementById('desk');

    ulTheme.eq(0).css('border-bottom','2px solid blue');
    bgwin.eq(0).on('mouseover',function(){
        ulOne.css('display','block');
        ulOne.siblings().css('display','none');
        ulTheme.eq(0).css('border-bottom','2px solid blue');
        ulTheme.eq(0).siblings().css('border-bottom','none');

    });
    bgwin.eq(1).on('mouseover',function(){
        ulTwo.css('display','block');
        ulTwo.siblings().css('display','none');
        ulTheme.eq(1).css('border-bottom','2px solid blue');
        ulTheme.eq(1).siblings().css('border-bottom','none');
    });
    bgwin.eq(2).on('mouseover',function(){
        ulThree.css('display','block');
        ulThree.siblings().css('display','none');
        ulTheme.eq(2).css('border-bottom','2px solid blue');
        ulTheme.eq(2).siblings().css('border-bottom','none');
    });
    ulWindowOne.eq(0).on('click',function(){
        leftBar.css('backgroundColor','#2050ab');
        // task.css('backgroundColor','#2050ab');
        // taskMenu.css('backgroundColor','#2050ab');
    });
    ulWindowOne.eq(1).on('click',function(){
        leftBar.css('backgroundColor','#346c1b');
        // task.css('backgroundColor','#346c1b');
        // taskMenu.css('backgroundColor','#346c1b');
    });
    ulWindowOne.eq(2).on('click',function(){
        leftBar.css('backgroundColor','#9b1dab');
        // task.css('backgroundColor','#9b1dab');
        // taskMenu.css('backgroundColor','#9b1dab');
    });
    ulWindowOne.eq(3).on('click',function(){
        leftBar.css('backgroundColor','#d09615');
        // task.css('backgroundColor','#d09615');
        // taskMenu.css('backgroundColor','#d09615');
    });
    ulWindowOne.eq(4).on('click',function(){
        leftBar.css('backgroundColor','#544a4a');
        // task.css('backgroundColor','#544a4a');
        // taskMenu.css('backgroundColor','#544a4a');
    });
    ulWindowOne.eq(5).on('click',function(){
        leftBar.css('backgroundColor','#2f8052');
        // task.css('backgroundColor','#2f8052');
        // taskMenu.css('backgroundColor','#2f8052');
    });

//    等级分类
//     $('#wrap').append('<div id="fenleiMenu"><div id="fenleiMenuTitle">等级分类</div><dl><dt>常用分类</dt><dt>工具类</dt><dt>资讯类</dt></dl></div>')
//     $('#wrap').append('<div id="fenleiMenu"><div class="triangle_border_up"></div><dl><dt>常用分类</dt><dt>工具类</dt><dt>资讯类</dt></dl></div>')

//     $('#fenlei').on('click',function(){
//         $('#fenleiMenu').toggle();
//     });


    //添加桌面与各个桌面之间的转换动作
//  wrap.append('<div id="upload_arrow" class="upload_arrow"></div><div id="down_arrow" class="down_arrow"></div>');
// 	var numButton = 1;
//
//  $("#fenleiMenu dl dt").on("click",function(){
//  	   $('#fenleiMenu').hide();
//  	    goToDesk($(this).index()+1);
//  })
//
//  $('#upload_arrow').on('click',function(){
//      if(numButton == 0 || numButton ==1){
//          numButton = deskss.children.length
//      }else{
//          numButton--
//      }
//		goToDesk(numButton);
//  });
//  $('#down_arrow').on('click',function(){
//      if(numButton >= 3 ){
//          numButton = 1
//      }else{
//          numButton++
//      }
//      goToDesk(numButton);
//
//  });
//
// function goToDesk(number){
//  	   $('#desk').children('#deskWrap'+number).fadeIn();
//          $('#desk').children('#deskWrap'+number).siblings().fadeOut()
//  }



});
